package com.china08.yxyapi.api.manage.tec.teaching.mistakes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.lecture.YxyLectureCatalog;
import com.china08.yxyapi.entity.mg.mistakes.TeaCenterMistakes;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.repository.mg.lecture.YxyLectureCatalogRepository;
import com.china08.yxyapi.repository.mg.mistakes.TeaCenterMistakesRepository;
import com.china08.yxyapi.security.profile.YxyProfile;

/**
 * 教师中心任教书籍章节记录保存
 * 
 * @author Administrator
 *
 */
@CrossOrigin
@RestController
public class TeaCenterMistakesBookContentCrtController extends YxyApiBaseController {

    @Autowired
    private TeaCenterMistakesRepository teaCenterMistakesRepository;

    @Autowired
    private YxyLectureCatalogRepository yxyLectureCatalogRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/mistakes/bookcontent/crt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel model) {
        YxyProfile yxyProfile = getProfile(request, response);
        String teaId = yxyProfile.getId();
        String schId = yxyProfile.getSchoolId();

        YxyLectureCatalog YxyLectureCatalo = yxyLectureCatalogRepository.findOne(model.id);
        Assert.notNull(YxyLectureCatalo, "改书籍记录不存在");

        TeaCenterMistakes centerMistakes = new TeaCenterMistakes();
        centerMistakes.setId(teaId + schId);
        centerMistakes.setTeacherId(teaId);
        centerMistakes.setSchoolId(schId);
        centerMistakes.setStage(YxyLectureCatalo.getPhaseId());
        centerMistakes.setStageName(YxyLectureCatalo.getPhaseName());
        centerMistakes.setSubject(YxyLectureCatalo.getSubjectId());
        centerMistakes.setSubjectName(YxyLectureCatalo.getSubjectName());
        centerMistakes.setVersion(YxyLectureCatalo.getVersionId());
        centerMistakes.setVersionName(YxyLectureCatalo.getVersionName());
        centerMistakes.setBookId(YxyLectureCatalo.getBookId());
        centerMistakes.setBookName(YxyLectureCatalo.getSemesterName());
        centerMistakes.setBookContent(model.bookContent);
        centerMistakes.setBookContentName(model.bookContentName);
        teaCenterMistakesRepository.save(centerMistakes);
    }

    /**
     * 请求参数
     * 
     */
    protected static class ReqModel extends YxyApiReqModel {
        // id
        public String id;

        // 章节id
        public String bookContent;

        // 章节name
        public String bookContentName;
    }
}
